import Cookies from 'js-cookie'
import cache from '@/plugins/cache'
const TokenKey = 'Admin-Token'

export function getToken() {
  if (cache.session.get(TokenKey)) {
    return cache.session.get(TokenKey)
  }
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  cache.session.set(TokenKey, token)
  Cookies.set(TokenKey, token)
}

export function removeToken() {
  cache.session.remove(TokenKey)
  return Cookies.remove(TokenKey);
}
//清除所有cookie函数
export function clearAllCookie() {
  const keys = document.cookie.match(/[^ =;]+(?==)/g);
  if(keys) {
    keys.forEach(function(key) {
      document.cookie = key + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC; domain=.zj.chinamobile.com; path=/";
    })
  }
}

